//
//  TxLoginStep.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/4/20.
//


import Combine

// 阿里云，一键登录
struct OnekeyLoginStep: LoginStep {
    struct InputData {
        let token: String
    }

    func execute(_ input: InputData) -> AnyPublisher<AuthAPI.OneKeyLogin.Response, Error> {
        Future { promise in
            let api = AuthAPI.OneKeyLogin(body: .init(token: input.token))
            NetworkManager.shared.send(api, completion: { result in
               switch result {
               case .success(let response):
                   if let response = response.data
                   {
                       Logger.log(.info, message: "一键登陆成功: \(response)",tag: .login)
                       promise(.success(response))
                   }
                   else{
                       promise(.failure(NSError(domain: "一键登录", code: response.code as! Int, userInfo: [NSLocalizedDescriptionKey: response.msg ?? "无错误描述"])))
                   }
               case .failure(let error):
                   promise(.failure(error))
               }
            })
        }
        .eraseToAnyPublisher()
    }
}
